package com.solver.demo.rscoket.v1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Controller
@Slf4j
public class V1RSocketController {

    @MessageMapping("request-response")
    public Mono<String> requestResponse(String request) {
        return Mono.just("Response to " + request);
    }

    @MessageMapping("request-stream")
    public Flux<String> requestStream(String request) {
        return Flux.just("Stream response 1", "Stream response 2", "Stream response 3");
    }

    @MessageMapping("fire-and-forget")
    public Mono<Void> fireAndForget(String request) {
        System.out.println("Received: " + request);
        return Mono.empty();
    }

    @MessageMapping("channel")
    public Flux<String> handleChannel(Flux<Message> messages) {
        return messages.map(message -> {
            // 根据groupId进行处理
            String groupId = message.getGroupId();
            String content = message.getContent();
            // 此处可以根据groupId来进行分组处理逻辑
            return "Processed " + content + " in group " + groupId;
        });
    }
}
